package com.rd.student.jike.class2.lihongming.week724_730.Day727;

import java.io.*;

/**
 * @Auther:Heinrich
 * @Date:2023/7/27-07-27-15:52
 * @Description:c230727
 * @version:1.0
 */
public class  TestBuffered {
    //效率更高
    public static void main(String[] args) throws Exception{
        File file = new File("stream.txt");
        FileInputStream fis = new FileInputStream(file);
        InputStream is = new BufferedInputStream(fis);
        byte[] arr = new byte[(int) file.length()] ;
        is.read(arr);
        System.out.println(new String(arr));
        is.close();
        fis.close();
        copyFlie("stream.txt","streamBuffer.txt");
    }

    public static void copyFlie(String srcPath,String descPath) throws Exception{
        InputStream is = new BufferedInputStream(
                new FileInputStream(srcPath));
        OutputStream os = new BufferedOutputStream(
                new FileOutputStream(descPath)
        );
        byte[] arr = new byte[1024];
        int len = 0;
        while ((len = is.read(arr))!=-1){
            os.write(arr,0,len);
        }
        //强制刷新
        os.flush();
        os.close();
        is.close();


    }
}
